package com.example.mvc.context;

import com.example.common.utils.Statistics;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import java.io.IOException;

@Slf4j
@Component
public class MyOncePerRequestFilter extends OncePerRequestFilter {

    private MyOncePerRequestFilter(){
        Statistics.logInfo(log);
    }

    @Override
    protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response,
                                    @NonNull FilterChain filterChain) throws ServletException, IOException {
        Statistics.logInfo(log, "doFilterInternal", request);
        filterChain.doFilter(request, response);
    }
}
